// https://leetcode.cn/problems/container-with-most-water/description/

// 算法思路总结：
// 1. 使用双指针从两端向中间移动
// 2. 计算当前指针围成的区域面积
// 3. 移动高度较小的指针以寻求更大面积
// 4. 时间复杂度：O(n)，空间复杂度：O(1)

#include <iostream>
using namespace std;

#include <vector>
#include <algorithm>

class Solution 
{
public:
    int maxArea(vector<int>& height) 
    {
        int n = height.size();
        int ret = 0;

        for (int l = 0, r = n - 1 ; l != r ; )
        {
            ret = max(ret, min(height[l], height[r]) * (r - l));

            if (height[l] > height[r]) r--;
            else l++;
        }

        return ret;
    }
};

int main()
{
    vector<int> h1 = {1,8,6,2,5,4,8,3,7}, h2 = {1,1};
    Solution sol;

    cout << sol.maxArea(h1) << endl;
    cout << sol.maxArea(h2) << endl;

    return 0;
}